package com.pencilisland.pay.core.mp.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.pencilisland.pay.api.bean.mp.core.MessageRequest;
import com.pencilisland.pay.api.bean.mp.core.MessageResponse;
import com.pencilisland.pay.api.bean.mp.core.WxappAccessTokenREQ;
import com.pencilisland.pay.api.bean.mp.core.WxappAccessTokenRES;
import com.pencilisland.pay.core.mp.service.MBService;
/**
* 报文逻辑处理.获取小程序ACCESS_TOKEN
*
* @author breeze
*/
import com.pencilisland.pay.core.service.WxappService;

@Service("MB_wxappAccessToken")
public class WxappAccessTokenMB implements MBService {

	@Autowired
	ObjectMapper objectMapper;

	@Autowired
	WxappService wxappService;

	@Override
	public MessageResponse process(MessageRequest request) {
		WxappAccessTokenRES res = new WxappAccessTokenRES(true, null, "OK");
		res.setAccessToken(wxappService.getAccessToken());
		return res;
	}

	public WxappAccessTokenREQ getRequestBody(MessageRequest request) {
		return objectMapper.convertValue(request.getBody(), WxappAccessTokenREQ.class);
	}

}
